package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.anno.AutoFill;
import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.enumeration.OperationType;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.*;

public interface SetmealMapper {

    /**
     * 根据分类id查询套餐的数量
     * @param id
     * @return
     */
    @Select("select count(id) from setmeal where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);
    /**
     * 根据id修改套餐
     *
     * @param setmeal
     */
    @AutoFill(OperationType.UPDATE)
    void update(Setmeal setmeal);
    /*
     * 套餐分页查询
     * */

    Page<SetmealVO> page(SetmealPageQueryDTO dto);
    /*
     * 修改套餐
     * */
    void selectById(SetmealDTO dto);

    @Options(useGeneratedKeys = true,keyProperty = "id")
    @AutoFill(OperationType.INSERT)
    @Insert("insert into setmeal values (null,#{categoryId},#{name},#{price}, #{status},#{description}," +
            "#{image}, #{createTime},#{updateTime},#{createUser}, #{updateUser})")
    void insertSetmeal(Setmeal setmeal);
    /*
     * 根据id查询套餐
     * */
    @Select("select * from setmeal where id=#{id}")
    Setmeal getById(Long id);

    @Delete("delete from setmeal where id=#{id}")
    void deleteById(Long id);
}
